package com.hy.study.driver;

import com.hy.study.inputformat.WholeFileInputFormat;
import com.hy.study.mapper.SequenceFileMapper;
import com.hy.study.reduce.SequenceFileReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;

/**
 * @author huyong
 * @date 2024 年 01 月 31 日 11:17: 57
 */
public class SequenceFileDriver {
    public static void main(String[] args) throws Exception {
        final String inputfile = "F:\\study\\Hadoop\\input\\data";
        final String outputfile = "F:\\study\\Hadoop\\output\\result3";
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setMapperClass(SequenceFileMapper.class);
        job.setReducerClass(SequenceFileReducer.class);

        // 设置自定义的切片
        job.setInputFormatClass(WholeFileInputFormat.class);
        job.setOutputFormatClass(SequenceFileOutputFormat.class);

        job.setJarByClass(SequenceFileDriver.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(BytesWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(BytesWritable.class);

        FileInputFormat.addInputPath(job, new Path(inputfile));
        FileOutputFormat.setOutputPath(job, new Path(outputfile));

        boolean completion = job.waitForCompletion(true);
        System.exit(completion ? 0 : 1);
    }
}
